home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Files
/
FileReader.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
1KB
|
64 lines
// FileReader.cp
#ifndef FileReader_h
#include "FileReader.h"
#endif
#ifndef Buffer_h
#include "Buffer.h"
#endif
#ifndef FileAccessPath_h
#include "FileAccessPath.h"
#endif
#ifndef FilePermissionError_h
#include "FilePermissionError.h"
#endif
#ifndef FileLockError_h
#include "FileLockError.h"
#endif
FileReader::FileReader( const FileAccessPath& theFile,
uint32 position )
: finished( false )
{
Assert( theFile.IsOpen() );
ioParam.ioCompletion = 0;
ioParam.ioRefNum = theFile.RefNum();
ioParam.ioPosMode = fsFromStart;
ioParam.ioPosOffset = position;
}
uint32 FileReader::operator>>( Buffer& buffer )
{
Assert( !Finished() );
ioParam.ioBuffer = reinterpret_cast<char *>( buffer.Unused().Start() );
ioParam.ioReqCount = buffer.Unused().Length();
OSErr error = PBReadSync( this );
buffer.AdvanceMark( ioParam.ioActCount );
if ( error == eofErr )
finished = true;
else
ThrowError( error );
return ioParam.ioActCount;
}
void FileReader::ThrowError( OSErr error )
{
if ( error == noErr )
return;
switch ( error )
{
case afpAccessDenied: throw FilePermissionError( error );
// This is a documented possibility: (?)
case fLckdErr: throw FileLockError( error );
}
throw FileError( error );
}